package tools.chapter23;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * @author Kevin
 * @date 2020/4/13 19:15
 */
public class FutureSubmitRunnableDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService executor = Executors.newFixedThreadPool(1);
        //创建Result对象r
        Result r = new Result(0);
        Future<Result> fr = executor.submit(new Task(r), r);
        System.out.println(fr.get().getAAA());

    }
    static class Task implements Runnable {
        Result T;
        //通过构造函数传入result
        Task(Result r) {
            this.T = r;
        }
        @Override
        public void run() {
            T.setAAA(666);
        }
    }
    static class Result{
        Integer a;
        Result(Integer a) {
            this.a = a;
        }
        Integer getAAA() {
            return a;
        }
        void setAAA(Integer a) {
            this.a = a;
        }
    }
}
